package cn.dw.mm.activiti;

import java.util.ArrayList;
import java.util.List;

import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.UserEntity;

import cn.dw.mm.domain.Role;

/**
 * 将业务中自己定义的用户、角色转化为activiti中使用的user、group
 */
public class ActivitiUserUtils {
    public static User toActivitiUser(cn.dw.mm.domain.User cusUser){
        User userEntity=new UserEntity();
        userEntity.setId(cusUser.getId());
        userEntity.setFirstName(cusUser.getName());
        userEntity.setLastName(cusUser.getName());
        userEntity.setPassword(cusUser.getPassword());
        return userEntity;
    }
    public static GroupEntity toActivitiGroup(Role cusRole){
        GroupEntity groupEntity=new GroupEntity();
        groupEntity.setRevision(1);
        groupEntity.setType("assignment");
        groupEntity.setId(cusRole.getId());
        groupEntity.setName(cusRole.getRoleName());
        return groupEntity;
    }
    public static List<Group> toActivitiGroups(List<Role> cusRoles){
        List<Group> groups=new ArrayList<Group>();
        for (Role role:cusRoles
             ) {
            GroupEntity groupEntity=toActivitiGroup(role);
            groups.add(groupEntity);
        }
        return groups;
    }
}
